package com.zh.recordscreen.util;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.util.Log;

import java.util.List;

/**
 * descrition:wifi
 */
public class WifiUtils {
    private Activity mContext;

    private static WifiUtils instance = null;
    private WifiUtils(){}
    public static synchronized WifiUtils getInstance(){
        if(instance == null) {
            instance = new WifiUtils();
        }
        return instance;
    }
    private WifiManager mWifiManager;
    public void init(Activity context){
        mWifiManager = (WifiManager) context.getApplicationContext().getSystemService(context.WIFI_SERVICE);
    }

    public void getWifiInfo(){
        WifiInfo wifiInfo= mWifiManager.getConnectionInfo(); //当前wifi连接信息
        Log.e("获取wifi信息 1",wifiInfo.toString());
        mWifiManager.startScan();
        List<ScanResult> scanResults = mWifiManager.getScanResults();//搜索到的设备列表
        Log.e("获取wifi信息 2",scanResults.toString());

        for (ScanResult scanResult : scanResults) {
            Log.e("获取wifi信息 3","\n设备名："+scanResult.SSID
                    +" 信号强度："+scanResult.level+"/n :"+mWifiManager.calculateSignalLevel(scanResult.level,4));
        }
    }

}
